package com.khh.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;

/**
 * Created by webrx on 2017-09-08.
 */

//@Component 通用组件 //@Controller 控制器 //@Service 业务 @Repository 数据库层
@Data
//@Controller("/stu")
@Repository("/st") @Scope("prototype") @Lazy //延迟加载，在第一次使用时加载
public class Student {

    @Value("22") //属性装配
    private int id;
    @Value("李四")
    private String name;
    @Value("北京")
    private String address;


    //@Resource(name = "teacher") //自动装配
    @Autowired  //自动装配 默认byname 没找到 按照bytype执行 bytype若有多个 报错
    private Teacher teacher;

    public Student(){
        System.out.println("构造方法");
    }

    @PreDestroy
    public void close(){

        System.out.println("close");
    }
    @PreDestroy
    public void closea(){

        System.out.println("close-a");
    }
    @PostConstruct
    public void inita(){
        System.out.println("inita");
    }
    @PostConstruct
    public void initb(){
        System.out.println("initb");
    }
    @PostConstruct
    public void initc(){
        System.out.println("initc");
    }
}
